function selectedAll() {
	var selectall = document.getElementById("selectall");
	var inputs = document.getElementsByTagName("input");
	for(var i = 0; i < inputs.length; i++) {
		if(inputs[i].type == "checkbox") {
			inputs[i].checked = selectall.checked;
		}
	}
	checkBox()

}

function del(t) {
	if(confirm("只能按顺序删！")) {

		var t = t.parentNode.parentNode.parentNode.children[0];
		var t2 = tab.children[0].children[1];
		tab.children[0].removeChild(t);
		tab.children[0].removeChild(t2);
		getAllSum();
		getAllSum1();
	}
}

function getTdSum(t) {
	var sum = 0;
	var t = t.parentNode.parentNode;
	sum = t.children[3].innerHTML * t.children[4].children[1].value;
	console.log(t.children[5].children[0].innerHTML)
	t.children[5].children[0].innerHTML = sum;

}

function getAllSum() {
	var sum = 0;
	var str = tab.children[0].children; //获取table里的每个tr
	//	console.log(str[1].children[3].innerHTML);
	for(var i = 1; i < str.length; i = i + 2) {
		sum += str[i].children[3].innerHTML * str[i].children[4].children[1].value;
	}
	document.getElementById("sum1").innerHTML = sum;
}

function getAllSum1() {
	var sum = 0;
	var str = tab.children[0].children; //获取table里的每个tr
	//	console.log(str[1].children[3].innerHTML);
	for(var i = 1; i < str.length; i = i + 2) {
		sum += (str[i].children[2].innerHTML) * 1
	}
	document.getElementById("sum2").innerHTML = sum;
}

function checkBox() {
	var inputs = document.getElementById("tab").getElementsByTagName("input");
	var str = tab.children[0].children;
	console.log(str[1].children[5].children[0].innerHTML);
	var sum = 0,
		sum2 = 0;

	for(var i = 0; i < str.length; i++) {
		if(str[i].children.length > 1) {
			if(str[i].children[0].children[0].checked == true) {
				sum += parseInt(str[i].children[5].children[0].innerHTML);
				sum2 += (inputs[i].parentNode.parentNode.children[2].innerHTML) * 1;

			}
		}
	}

	document.getElementById("sum1").innerHTML = sum;
	document.getElementById("sum2").innerHTML = sum2;

}

function delAll() {
	//	var inputs = document.getElementById("tab").getElementsByTagName("input");
	//	for(var i = 0; i < inputs.length; i++) {
	//		if(inputs[i].checked) {
	//			var t = t.parentNode.parentNode.parentNode.children[i];
	//			var t2 = tab.children[0].children[i+1];
	//			tab.children[0].removeChild(t);
	//			tab.children[0].removeChild(t2);
	//		}
	//	}
}

function add(t) {
	t.parentNode.children[1].value++;
	getTdSum(t);
	checkBox();

}

function minus(t) {
	if(t.parentNode.children[1].value > 1) {
		var num = t.parentNode.children[1].value--;
		getTdSum(t);
		checkBox()
	} else {
		confirm("数量至少大于0")
	}

}

function addNew() {
	var tr = document.createElement("tr");
	tr.innerHTML = '<td colspan="7">店铺： <a href="#"> 红豆豆的小屋</a> 卖家： <a href="#"> taobao豆豆</a> <img style="vertical-align: middle;" src="img/taobao_relation.jpg" /></td>';
	tr.className="t1"
	tab.children[0].appendChild(tr)
	var tr1 = document.createElement("tr");
	tr1.innerHTML = '<td class="d1"><input type="checkbox" name="box" id="" value="" onclick="checkBox()" /></td>';
	tr1.innerHTML += '<td class="d2"><img class="t9" src="img/taobao_cart_04.jpg" /><div class="t0"><a href="#">相宜促销专供 大S推荐 最好用的LilyBell化妆棉</a><br/>保障：<img src="img/taobao_icon_01.jpg" /> </div></td>'
	tr1.innerHTML += '<td class="d3">10</td>';
	tr1.innerHTML += '<td class="d4">15.00</td>';
	tr1.innerHTML += '<td class="d5"><img src="img/taobao_minus.jpg" onclick="minus(this)"/><input type="text" size="1" value="2" onblur="getTdSum(this)" /><img src="img/taobao_adding.jpg" onclick="add(this)" /></td>';
	tr1.innerHTML += '<td class="d6"><span id="tdsum">30</span></td>';
	tr1.innerHTML += '<td class="d7"><a href="#" onclick="del(this)">删除</a></td>';
	tr1.className="t2"
	tab.children[0].appendChild(tr1);
	checkBox();
}